package net.htjs.mobile.android.crm;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class LoadActivity extends Activity {
	ConnectivityManager cgr;
	NetworkInfo netinfo;
	TelephonyManager tm;

	@Override
	protected void onStart() {
		super.onStart();
		
		//判断网络运营商
		//String ism=tm.getSimOperator();
		/* String ism=tm.getSubscriberId();
		 if(null==ism||ism.equals("")){//没装sim卡
			Util.dialog(Main.this, "SIM卡不存在", "关闭应用", "继续操作", Main.this,
					"finish", null, Main.this, "finish", null, false);
			return;
		}else{
			if(!(ism.startsWith("46000")||ism.startsWith("46002"))){//不是中国移动
				
				Util.dialogOnlyCommit(Main.this, "本应用仅供移动用户使用", "关闭应用", "确定", Main.this,
						"finish", null);
				return;
			}else{//如果是移动号码，继续往下操作
			}
		} */
		netinfo = cgr.getActiveNetworkInfo();
		System.out.println(netinfo);
		State mobile = cgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
				.getState();

		State wifi = cgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();

		if (mobile == State.CONNECTED || mobile == State.CONNECTING
				|| wifi == State.CONNECTED || wifi == State.CONNECTING) {
			this.jumpToTabPage();
			return;
		} else {
			return;
			//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));// 进入无线网络配置界面
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.load);
		setTitle(R.string.app_name);
		tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);//获取sim卡信息
		cgr = (ConnectivityManager) this
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		getWindow().setFormat(PixelFormat.RGBA_8888);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
		try {
			TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
			versionNumber.setText("Version " + "1.0");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void jumpToTabPage() {
		new Handler().postDelayed(new Runnable() {
			public void run() {
				Intent mainIntent = new Intent(getApplication(),
						LoginActivity.class);
				LoadActivity.this.startActivity(mainIntent);
				LoadActivity.this.finish();
				overridePendingTransition(android.R.anim.fade_in,
						android.R.anim.fade_out);
			}
		}, 1500);
	}

	public void onPause() {
		super.onPause();
	}

	public void onDestory() {
		super.onDestroy();
	}
}
